﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PropertyManagement.Core.DataAccess;
using PropertyManagement.Core.Model;

namespace PropertyManagement.Core {
    public class HouseOwnerManage {

        public bool Add(HouseOwner houseOwner) {
            if (!string.IsNullOrWhiteSpace(houseOwner.OwnerName) && string.IsNullOrWhiteSpace(houseOwner.ApartmentName)) {

                if (!HouseOwnerDataAccess.ExistsByPKs(houseOwner)) {
                    HouseOwnerDataAccess.Add(houseOwner);
                    return true;
                }
            }

            return false;
        }

        public void Update(HouseOwner houseOwner) {


            if (!string.IsNullOrEmpty(houseOwner.HouseCode)) {
                HouseOwnerDataAccess.Update(houseOwner);
            }
        }

        public HouseOwner Load(string houseCode) {

            //throw new NotImplementedException( );
            return HouseOwnerDataAccess.GetByPKs(new HouseOwner { HouseCode = houseCode });
        }

        public void Remove(string houseCode) {

            //throw new NotImplementedException( );
            var houseOwner = Load(houseCode);
            HouseOwnerDataAccess.Remove(houseOwner);
        }

        public IEnumerable<HouseOwner> LoadAll( ) {
            return HouseOwnerDataAccess.LoadAll( );
        }
    }
}
